package com.hxz.graduationdesign.controller;

import com.hxz.graduationdesign.base.response.JsonResult;
import com.hxz.graduationdesign.pojo.vo.CommentVo;
import com.hxz.graduationdesign.pojo.vo.GenderVo;
import com.hxz.graduationdesign.pojo.vo.LevelVo;
import com.hxz.graduationdesign.pojo.vo.ReplyCommentVo;
import com.hxz.graduationdesign.service.ICommentService;
import com.hxz.graduationdesign.util.ChineseSegmenter;
import com.hxz.graduationdesign.util.SentimentAnalyzer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

import static com.hxz.graduationdesign.base.response.StatusCode.COMMENT_ADD_FAILED;
import static com.hxz.graduationdesign.util.BilibiliCommentCrawler.getVideoComments;
import static com.hxz.graduationdesign.util.FormattingTool.getChineseSegmenter;
import static com.hxz.graduationdesign.util.FormattingTool.getSentimentAnalyzer;

@Slf4j
@RestController
@RequestMapping("/v1/comment/")
public class CommentController {

    @Autowired
    private ICommentService commentService;

    @PostMapping("segmenter/{bv}")
    public JsonResult getSegmenter(@PathVariable String bv){
        Map<String, Integer> segmenter = commentService.segmenter(bv);
        return JsonResult.ok(segmenter);
    }

    @PostMapping("query/{bv}")
    public JsonResult queryComment(@PathVariable String bv) {

        log.debug("查询一级评论视频bv号："+bv);

        Map<String, Object> commentMap = commentService.queryComment(bv);

        return JsonResult.ok(commentMap);
    }

    @PostMapping("queryGender/{bv}")
    public JsonResult queryGender(@PathVariable String bv){

        log.debug("查询{}视频评论性别",bv);
        List<GenderVo> genderVos = commentService.queryGender(bv);
        return JsonResult.ok(genderVos);

    }

    @PostMapping("queryLevel/{bv}")
    public JsonResult queryLevel(@PathVariable String bv){

        log.debug("查询{}视频评论性别",bv);
        List<LevelVo> levelVos = commentService.queryLevel(bv);
        return JsonResult.ok(levelVos);

    }

    @PostMapping("update/{bv}")
    public JsonResult updateComment(@PathVariable String bv){
        log.debug("更新{}视频评论",bv);
        Map<String, Object> stringObjectMap = commentService.updateComment(bv);

        return JsonResult.ok(stringObjectMap);
    }

    @PostMapping("emo/{bv}")
    public JsonResult emo(@PathVariable String bv){

        Map<String, Integer> emo = commentService.emo(bv);

        return JsonResult.ok(emo);

    }

}
